package com.chao.common.util.secure;

import cn.hutool.core.util.StrUtil;

/**
 * @author: bihf
 * @Date: 2021/4/23 17:25
 */
public class SecureUtil {

    public static String secureCard(String card) {
        if (card == null) {
            return card;
        }
        char[] idchars = card.toCharArray();
        for (int i = 3; i < card.length() - 4; i++) {
            idchars[i] = '*';
        }

        return new String(idchars);
    }

    public static String secureIdcard(String idcard) {
        if (idcard == null) {
            return idcard;
        }
        char[] idchars = idcard.toCharArray();
        for (int i = 5; i < idcard.length() - 4; i++) {
            idchars[i] = '*';
        }

        return new String(idchars);
    }

    public static String secureXm(String xm) {
        if (StrUtil.isBlank(xm)) {
            return xm;
        }
        char[] xmChars = xm.toCharArray();
        for (int i = 1; i < xmChars.length; i++) {
            xmChars[i] = '*';
        }

        return new String(xmChars);
    }

    public static String secureUsername(String username) {
        if (StrUtil.isBlank(username)) {
            return username;
        }
        char[] xmChars = username.toCharArray();
        for (int i = 1; i < xmChars.length-1; i++) {
            xmChars[i] = '*';
        }

        return new String(xmChars);
    }

    public static void main(String[] args)
    {
        System.out.println(secureMobile(""));
    }

    public static String secureMobile(String mobile) {
        if (StrUtil.isBlank(mobile)) {
            return mobile;
        }
        char[] idchars = mobile.toCharArray();
        for (int i = 3; i < mobile.length() - 4; i++) {
            idchars[i] = '*';
        }

        return new String(idchars);
    }
}
